package com.cw.mybatis.starter.converter;

import com.cw.mybatis.starter.model.BaseDo;
import com.cw.starter.center.dto.BaseDto;

/**
 * 基础转换类
 *
 * @author chenw
 * @date 2021/11/10
 */
public class BaseConverter {
    /**
     * dto转do
     *
     * @param baseDto
     * @return
     */
    public static BaseDo dto2Do(BaseDto baseDto) {
        if(baseDto == null){
            return null;
        }
        return BaseDo.builder()
            .id(baseDto.getId())
            .deleted(baseDto.getDeleted())
            .version(baseDto.getVersion())
            .createBy(baseDto.getCreateBy())
            .createTime(baseDto.getCreateTime())
            .createTimeStart(baseDto.getCreateTimeStart())
            .createTimeEnd(baseDto.getCreateTimeEnd())
            .updateBy(baseDto.getUpdateBy())
            .updateTime(baseDto.getUpdateTime())
            .updateTimeStart(baseDto.getUpdateTimeStart())
            .updateTimeEnd(baseDto.getUpdateTimeEnd())
            .build();
    }

    /**
     * do转dto
     *
     * @param baseDo
     * @return
     */
    public static BaseDto do2Dto(BaseDo baseDo) {
        if(baseDo == null){
            return null;
        }
        return BaseDto.builder()
            .id(baseDo.getId())
            .deleted(baseDo.getDeleted())
            .version(baseDo.getVersion())
            .createBy(baseDo.getCreateBy())
            .createTime(baseDo.getCreateTime())
            .createTimeStart(baseDo.getCreateTimeStart())
            .createTimeEnd(baseDo.getCreateTimeEnd())
            .updateBy(baseDo.getUpdateBy())
            .updateTime(baseDo.getUpdateTime())
            .updateTimeStart(baseDo.getUpdateTimeStart())
            .updateTimeEnd(baseDo.getUpdateTimeEnd())
            .build();
    }
}
